package com.ruoyi.syf.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.syf.domain.RiskShutdownRecord;
import com.ruoyi.syf.domain.vo.RiskShutdownRecordVo;
import com.ruoyi.syf.service.IRiskShutdownRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 开停工记录
 *
 * @author ruoyi
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/syf/shutdownRecord")
public class RiskShutdownRecordController extends BaseController {
    @Autowired
    private IRiskShutdownRecordService riskShutdownRecordService;

    /**
     * 查询开停工记录列表
     */
    @PreAuthorize("@ss.hasPermi('syf:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiskShutdownRecord riskShutdownRecord) {
        startPage();
        List<RiskShutdownRecordVo> list = riskShutdownRecordService.list(riskShutdownRecord);
        return getDataTable(list);
    }

    /**
     * 导出开停工记录列表
     */
    @PreAuthorize("@ss.hasPermi('syf:record:export')")
    @Log(title = "开停工记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskShutdownRecord riskShutdownRecord) {
        List<RiskShutdownRecordVo> list = riskShutdownRecordService.list(riskShutdownRecord);
        ExcelUtil<RiskShutdownRecordVo> util = new ExcelUtil<>(RiskShutdownRecordVo.class);
        util.exportExcel(response, list, "开停工记录数据");
    }

    /**
     * 获取开停工记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('syf:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(riskShutdownRecordService.selectRiskShutdownRecordById(id));
    }

    /**
     * 新增开停工记录
     */
    @PreAuthorize("@ss.hasPermi('syf:record:add')")
    @Log(title = "开停工记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskShutdownRecord riskShutdownRecord) {
        return toAjax(riskShutdownRecordService.insertRiskShutdownRecord(riskShutdownRecord));
    }

    /**
     * 修改开停工记录
     */
    @PreAuthorize("@ss.hasPermi('syf:record:edit')")
    @Log(title = "开停工记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskShutdownRecord riskShutdownRecord) {
        return toAjax(riskShutdownRecordService.updateRiskShutdownRecord(riskShutdownRecord));
    }

    /**
     * 删除开停工记录
     */
    @PreAuthorize("@ss.hasPermi('syf:record:remove')")
    @Log(title = "开停工记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(riskShutdownRecordService.deleteRiskShutdownRecordByIds(ids));
    }
}
